<?php
require_once("lib/db_connection.php");
$company_id = $_SESSION['company_id'];
$p1 = $_GET['p1'];
$p2 = $_GET['p2'];
$p3 = $_GET['p3'];

if($p1=='due')
{
$p4='veh_reminder_tbl.due_hours';
$p5='veh_reminder_tbl.due_date';

if($p2=='LIKE')
$passed_where_due = $p4." ".$p2." '%".$p3."%'"."||".$p5." ".$p2." '%".$p3."%'";
if($p2!='LIKE')
$passed_where_due = $p4." ".$p2." '".$p3."'"."||".$p5." ".$p2." '".$p3."'";
}

if($p1!='due')
{
if($p2=='LIKE')
$passed_where = $p1." ".$p2." '%".$p3."%'";
if($p2!='LIKE')
$passed_where = $p1." ".$p2." '".$p3."'";
}


if($p3=='')
{
$query_reminder = "SELECT 
veh_reminder_tbl.*,veh_reminder_tbl.vehicle_id as v_num,
vehicle_tbl.*,vehicle_tbl.vehicle_id as r_id 
FROM veh_reminder_tbl 
JOIN vehicle_tbl 
ON veh_reminder_tbl.vehicle_id=vehicle_tbl.vehicle_id
WHERE veh_reminder_tbl.company_id='".$company_id."'";
}

if($p3!=''||$p3!=null)
{
	if($p1=='due')
	{
	$query_reminder = "SELECT 
	veh_reminder_tbl.*,veh_reminder_tbl.vehicle_id as v_num,
	vehicle_tbl.*,vehicle_tbl.vehicle_id as r_id 
	FROM veh_reminder_tbl 
	JOIN vehicle_tbl 
	ON veh_reminder_tbl.vehicle_id=vehicle_tbl.vehicle_id
	WHERE veh_reminder_tbl.company_id='".$company_id."'
	AND ".$passed_where_due;	
	}

	if($p1!='due')
	{
	$query_reminder = "SELECT 
	veh_reminder_tbl.*,veh_reminder_tbl.vehicle_id as v_num,
	vehicle_tbl.*,vehicle_tbl.vehicle_id as r_id 
	FROM veh_reminder_tbl 
	JOIN vehicle_tbl 
	ON veh_reminder_tbl.vehicle_id=vehicle_tbl.vehicle_id
	WHERE veh_reminder_tbl.company_id='".$company_id."'
	AND ".$passed_where;	
	}	
}
$result_reminder = mysql_query($query_reminder)or die(mysql_error());
?>
<html>
<head>
<style type="text/css">
table,th,td
{
border:1.5px solid;
border-collapse:collapse;
}
</style>
<script type='text/javascript'>
function OpenExcel()
{
	var p1 = document.getElementById('p1').value;
	var p2 = document.getElementById('p2').value;
	var p3 = document.getElementById('p3').value;
	window.open('reminder_to_excel.php?p1='+p1+'&p2='+p2+'&p3='+p3,'SendToExcel');
}
</script>
</head>
<body>
<table width='100%' style='margin-left:auto;margin-right:auto;font-size:12px;font-family:Times New Roman'>	
<tr>	
		<th width='3%' colspan='1' style="background-color:gray">Plate</th>
		<th width='3%' colspan='1' style="background-color:gray">Year</th>
		<th width='3%' colspan='1' style="background-color:gray">Make</th>
		<th width='3%' colspan='1' style="background-color:gray">Model</th>
		<th width='3%' colspan='1' style="background-color:gray">Scheduled By</th>
		<th width='3%' colspan='1' style="background-color:gray">Due</th>
		<th width='5%' colspan='1' style="background-color:gray">Type</th>
		<th width='3%' colspan='1' style="background-color:gray">Description</th>
		<th width='3%' colspan='1' style="background-color:gray">Vendor</th>
</tr>
		
		<?php
		while($row_reminder = mysql_fetch_array($result_reminder))
		{
			//TRACKING
			$tracking = $row_reminder['schedule_by'];
			if($tracking=='Mileage')
			$due = $row_reminder['due_hours'].'Km';
			
			if($tracking=='Hours')
			$due = $row_reminder['due_hours'].'Hrs';
			
			if($tracking=='Date')
			$due = $row_reminder['due_date'];
			
		?>
		<tr>
			<!--REMINDER-->
			<td style="text-align:center;">&nbsp;<?php echo $row_reminder["veh_num"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_reminder["year"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_reminder["manufacturer_name"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_reminder["model_name"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_reminder["schedule_by"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $due ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_reminder["type"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_reminder["description"] ?>&nbsp;</td>
			<td style="text-align:center;">&nbsp;<?php echo $row_reminder["vendor"] ?>&nbsp;</td>
		</tr>
		<?php
		}
		?>
</table>
<br />
<input id="p1" type="hidden" value='<?php echo $p1 ?>' />
<input id="p2" type="hidden" value='<?php echo $p2 ?>' />
<input id="p3" type="hidden" value='<?php echo $p3 ?>' />
<input type="submit" value="Send to Excel" style='margin-left:auto;margin-right:auto;font-size:12px;font-family:Times New Roman' onClick=OpenExcel() />
</body>
</html>
		
